<?php

/**
 * @Author:      zh
 * @DateTime:    2015-10-08 11:44:44
 * @Description: 用于维护 erp 耗材 的单位
 *
 */

class DataSupplyUnit extends Eloquent
{

    protected $connection = 'mysql_data';
    protected $table = "supply_unit";

    /**
     * @Author: zk
     * @Date:   18-6-6 上午10:06
     * @Description:        获取耗材单位列表
     * @param int $status   单位状态 [默认为1:开启; 其它值则为获取全部状态]
     * @param int $type     返回结果类型 [1:id和name组合的二维数组; 2:id为key，name为value的一维数组;]
     * @return array
     */
    public static function getSupplyUnitList($status = 1, $type = 1) {
        $list = DataSupplyUnit::select('id', 'name');
        if($status == 1){
            $list->where('status', 1);
        }
        $list = $list->get()->toArray();
        if($type == 1){
            return $list;
        } else {
            $unit_list = [];
            if(!empty($list)){
                foreach ($list as $v) {
                    $unit_list[$v['id']] = $v['name'];
                }
            }
            return $unit_list;
        }
    }
    
}
